package com.ruoyi.business.service.impl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.ruoyi.business.domain.TDSsq;
import com.ruoyi.business.mapper.TDSsqMapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.TDSsqBetMapper;
import com.ruoyi.business.domain.TDSsqBet;
import com.ruoyi.business.service.ITDSsqBetService;

/**
 * 双色球投注Service业务层处理
 * 
 * @author lx
 * @date 2022-02-28
 */
@Service
public class TDSsqBetServiceImpl implements ITDSsqBetService 
{
    @Autowired
    private TDSsqBetMapper tDSsqBetMapper;
    @Autowired
    private TDSsqMapper tdSsqMapper;

    /**
     * 查询双色球投注
     * 
     * @param id 双色球投注主键
     * @return 双色球投注
     */
    @Override
    public TDSsqBet selectTDSsqBetById(Long id)
    {
        return tDSsqBetMapper.selectTDSsqBetById(id);
    }

    /**
     * 查询双色球投注列表
     * 
     * @param tDSsqBet 双色球投注
     * @return 双色球投注
     */
    @Override
    public List<TDSsqBet> selectTDSsqBetList(TDSsqBet tDSsqBet)
    {
        List<TDSsqBet> list=tDSsqBetMapper.selectTDSsqBetList(tDSsqBet);
        for (TDSsqBet bet:list){
            if(bet.getState() == 1){
                TDSsq ssq= tdSsqMapper.selectTDSsqById(bet.getStage());
                if (ssq!=null){
                    Set<String> lot=new HashSet<>();
                    lot.add(ssq.getOne());
                    lot.add(ssq.getTwo());
                    lot.add(ssq.getThree());
                    lot.add(ssq.getFour());
                    lot.add(ssq.getFive());
                    lot.add(ssq.getSix());
                    if (lot.contains(bet.getOne())){
                        bet.setOneWin("true");
                    }
                    if (lot.contains(bet.getTwo())){
                        bet.setTwoWin("true");
                    }
                    if (lot.contains(bet.getThree())){
                        bet.setThreeWin("true");
                    }
                    if (lot.contains(bet.getFour())){
                        bet.setFourWin("true");
                    }
                    if (lot.contains(bet.getFive())){
                        bet.setFiveWin("true");
                    }
                    if (lot.contains(bet.getSix())){
                        bet.setSixWin("true");
                    }
                    if (ssq.getSeven().equals(bet.getSeven())){
                        bet.setSevenWin("true");
                    }
                    bet.setHistory(ssq.getOne()+" "+ssq.getTwo()+" "+ssq.getThree()+" "+ssq.getFour()+" "+ssq.getFive()+" "+ssq.getSix()+"-"+ssq.getSeven());
                }
            }
        }
        return list;
    }

    /**
     * 新增双色球投注
     * 
     * @param tDSsqBet 双色球投注
     * @return 结果
     */
    @Override
    public int insertTDSsqBet(TDSsqBet tDSsqBet)
    {
        tDSsqBet.setCreateTime(DateUtils.getNowDate());
        return tDSsqBetMapper.insertTDSsqBet(tDSsqBet);
    }

    /**
     * 修改双色球投注
     * 
     * @param tDSsqBet 双色球投注
     * @return 结果
     */
    @Override
    public int updateTDSsqBet(TDSsqBet tDSsqBet)
    {
        tDSsqBet.setUpdateTime(DateUtils.getNowDate());
        return tDSsqBetMapper.updateTDSsqBet(tDSsqBet);
    }

    /**
     * 批量删除双色球投注
     * 
     * @param ids 需要删除的双色球投注主键
     * @return 结果
     */
    @Override
    public int deleteTDSsqBetByIds(Long[] ids)
    {
        return tDSsqBetMapper.deleteTDSsqBetByIds(ids);
    }

    /**
     * 删除双色球投注信息
     * 
     * @param id 双色球投注主键
     * @return 结果
     */
    @Override
    public int deleteTDSsqBetById(Long id)
    {
        return tDSsqBetMapper.deleteTDSsqBetById(id);
    }
}
